class Person {
    // 私有属性类型声明
    name: string;
    age: number;

    constructor(name: string, age: number) {
        this.name = name;
        this.age = age;
    }

    say(): void {
        console.log(this.name, this.age);
    }
}

let p1 = new Person('yuonly', 19)
console.log(p1);
p1.say();


// 2. 继承
class Programmer extends Person {
    skill: string;

    constructor(name: string, age: number, skill: string) {
        super(name, age);
        this.skill = skill
    }

    info(): void {
        console.log(this.name, this.age, this.skill);
    }
}


let pro1 = new Programmer('巩开拓', 30, 'javascript');

console.log(pro1);
pro1.info();


/**
 * 和java类似
 成员修饰符
 类内部          继承子类            类外部
 public[公开的]            y                y                  y
 protected[受保护的]       y                y                  n
 private[私有的]           y                n                  n
 *
 */

class Father {
    public name: string;
    protected money: number;
    private secret: string;

    constructor(name: string, money: number, secret: string) {
        this.name = name;
        this.money = money;
        this.secret = secret;
    }

    say(): void {
        console.log('public: ', this.name);
        console.log('protected: ', this.money);
        console.log('private: ', this.secret);
    }
}

class Son extends Father {
    constructor(name: string, money: number, secret: string) {
        super(name, money, secret);
    }

    hello(): void {
        console.log('public name: ', this.name);
        console.log('protected money: ', this.money);
        // console.log('private secret: ', this.secret); // 报错，私有属性子类无法访问
    }
}

let s1 = new Son('s', 20, '我觉得开发');
console.log(s1.name);
// console.log(s1.money);
// console.log(s1.secret);


export {}
